/**
 * @author JackGao
 *			email:jackgao.china@gmail.com
 *  date：2016-6-23
 * 
 */
package cn.cuit.ds.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.springframework.stereotype.Repository;

import cn.cuit.ds.dao.IOrdersDao;
import cn.cuit.ds.domain.Orders;
import cn.cuit.ds.utils.JdbcUtils;

@Repository(value="OrdersDao")
public class OrdersDao implements IOrdersDao {

	public void add(Orders orders) {
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql = "insert into orders values(?,?,?,?,?,?,?)";
		try {
			runner.update(sql, orders.getOrdersId(),orders.getShoperId(),orders.getOrderTime(),orders.getOrderName(),
					"未通过审核",orders.getDetail2(),orders.getAddressId());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	
	}

	public List<Orders> getAllByShoperId(String shoperId) {
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql = "select * from orders where shoperId = ?";
		try {
			return runner.query(sql, new BeanListHandler<Orders>(Orders.class),shoperId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return null;
	}

	public List<Orders> getAllByAddressId(String addressId) {
		
		QueryRunner runner = JdbcUtils.getQueryRunner();
		String sql = "select * from orders where addressId = ?";
		try {
			return runner.query(sql, new BeanListHandler<Orders>(Orders.class),addressId);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return null;
	}

}
